﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI.WebControls;
using Microsoft.Win32;
using System.IO;

/// <summary>
///Common 的摘要说明
/// </summary>
public class Common
{
    public Common()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    /// <summary>
    /// 返回选择的ID
    /// </summary>
    /// <param name="gv"></param>
    /// <returns></returns>
    public static string GetGvID(GridView gv)
    {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < gv.Rows.Count; i++)
        {
            if (((CheckBox)gv.Rows[i].Cells[0].FindControl("chkCheckBox")).Checked)
            {
                sb.Append(((Label)gv.Rows[i].Cells[0].FindControl("lbCheckBox")).Text);
                sb.Append(",");
            }
        }
        if (sb.Length == 0)
        {
            return null;
        }
        else
        {
            return sb.ToString().Substring(0, sb.ToString().LastIndexOf(","));
        }
    }

    public static string ChangeSQLQuery(string strOld)
    {
        string strNew = "";
        foreach (char c in strOld)
        {
            strNew += '[' + c.ToString() + ']';
        }
        return strNew;
    }
    public static string GetSchoolID(string schoolID)
    {

        int SchoolID = int.Parse(schoolID);
        if (SchoolID > 0 && SchoolID < 10)
        {
            return "00" + schoolID;
        }
        else
        {
            if (SchoolID >= 10 && SchoolID < 100)
            {
                return "0" + schoolID;
            }
            else
            {
                return schoolID;
            }
        }
    }
    /// <summary> 
    /// Self_Variable:查询注册表某个键值是否存在 
    /// </summary> 
    /// <returns></returns> 
    public static int ExistsRegedit()
    {
        int ifused = 2003;
        RegistryKey rk = Registry.LocalMachine;
        RegistryKey akey = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\11.0\\Word\\InstallRoot\\");
        RegistryKey akeytwo = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\");
        //检查本机是否安装Office2003
        if (akey != null)
        {
            string file03 = akey.GetValue("Path").ToString();
            if (File.Exists(file03 + "Excel.exe"))
            {
                ifused = 2003;
            }
        }
        //检查本机是否安装Office2007
        if (akeytwo != null)
        {
            string file07 = akeytwo.GetValue("Path").ToString();
            if (File.Exists(file07 + "Excel.exe"))
            {
                ifused = 2007;
            }
        }
        return ifused;
    }
}